<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>千锋留言板</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            padding: 100px;
        }
        
        textarea {
            width: 200px;
            height: 100px;
            border: 1px solid pink;
            outline: none;
            resize: none;
        }
        
        ul {
            margin-top: 50px;
        }
        
        li {
            width: 300px;
            padding: 5px;
            background-color: rgb(245, 209, 243);
            color: red;
            font-size: 14px;
            margin: 15px 0;
        }
        
        li a {
            float: right;
        }
    </style>
</head>

<body>
    <textarea name="" id=""></textarea>
    <button>发布</button>
    <ul>
	
    </ul>
    <script>
        // 获取元素 
        var btn = document.querySelector('button');
        var textarea = document.querySelector('textarea');
        var ul = document.querySelector('ul');


        btn.onclick = function(){
            if(textarea.value == ''){
                alert('您还没有输入内容')
                return 
            }else{
            // 获取表单输入内容 
            
            // 创建节点 
            var li = document.createElement('li');
            // 给创建的节点内容赋值
            li.innerHTML = textarea.value+'<a href="javascript:;">删除</a>';
            textarea.value = '';

            ul.insertBefore(li,ul.children[0]);
            }
           
        }
       
    </script>
</body>

</html>